using System;
using UnityEngine;
#if UNITY_EDITOR
using UnityEditor;
using UnityEditor.ProjectWindowCallback;
#endif
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.Serialization;

[Serializable]
public class CameraHeightRendererData : ScriptableRendererData
{
#if UNITY_EDITOR
    [MenuItem("Assets/Create/Rendering/Create CameraHeight Renderer", priority = CoreUtils.assetCreateMenuPriority2)]
    static void CreateForwardRendererData()
    {
        ProjectWindowUtil.StartNameEditingIfProjectWindowExists(0, CreateInstance<CameraHeightRendererAsset>(), "CameraHeight Renderer.asset", null, null);
    }

    internal class CameraHeightRendererAsset : EndNameEditAction
    {
        public override void Action(int instanceId, string pathName, string resourceFile)
        {
            var instance = CreateInstance<CameraHeightRendererData>();
            AssetDatabase.CreateAsset(instance, pathName);
            ResourceReloader.ReloadAllNullIn(instance, UniversalRenderPipelineAsset.packagePath);
            Selection.activeObject = instance;
        }
    }
#endif

    [FormerlySerializedAs("m_OpaqueLayerMask")] [SerializeField] 
    private LayerMask m_opaqueLayerMask = -1;

    /// <summary>
    /// Use this to configure how to filter opaque objects.
    /// </summary>
    public LayerMask OpaqueLayerMask
    {
        get => m_opaqueLayerMask;
        set
        {
            SetDirty();
            m_opaqueLayerMask = value;
        }
    }

    protected override ScriptableRenderer Create()
    {
        return new CameraHeightRenderer(this);
    }
}